//
//  ViewController.m
//  OberverTest
//
//  Created by ma c on 2017/8/17.
//  Copyright © 2017年luojianzhen. All rights reserved.
//

#import "ViewController.h"
#import "TestObject.h"
#import "NSObject+Observer.h"
@interface ViewController ()

@property (nonatomic,strong)TestObject *object;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.object = [[TestObject alloc] init];
    self.object.value = @"100";
    self.object.count = 1;
    
    [self addMonitor:self.object key:@"value" option:NSKeyValueObservingOptionNew callback:^(NSString *key, id object, NSDictionary<NSKeyValueChangeKey,id> *change) {
        NSLog(@"new value %@",change[NSKeyValueChangeNewKey]);

    }];
    [self addMonitor:self.object key:@"count" option:NSKeyValueObservingOptionNew callback:^(NSString *key, id object, NSDictionary<NSKeyValueChangeKey,id> *change) {
        NSLog(@"new count %@",change[NSKeyValueChangeNewKey]);
    }];
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)changevalueaction:(id)sender {
    self.object.value = @"200";
    self.object.count += 1;
//    [self.object setValue:@"200" forKey:@"value"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
